﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TruongVu.Data;

namespace TruongVu.Business
{
    public class ServiceModel
    {
        public IList<Service> GetServiceAccountingList()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 1
                        select service).ToList();
            return data;
        }

        public IList<Service> GetServiceIncorpotationList()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 2
                        select service).ToList();
            return data;
        }

        public IList<Service> GetServiceTaxReportList()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 3
                        select service).ToList();
            return data;
        }

        public IList<Service> GetServiceVisaList()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 4
                        select service).ToList();
            return data;
        }

        public IList<Service> GetServiceWorkPermitList()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 5
                        select service).ToList();
            return data;
        }

        public IList<Service> GetAirTicketList()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 6
                        select service).ToList();
            return data;
        }

        public Service GetServiceAccounting()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 1
                        select service).SingleOrDefault();
            return data;
        }

        public Service GetServiceIncorpotation()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 2
                        select service).SingleOrDefault();
            return data;
        }

        public Service GetServiceTaxReport()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 3
                        select service).SingleOrDefault();
            return data;
        }

        public Service GetServiceVisa()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 4
                        select service).SingleOrDefault();
            return data;
        }

        public Service GetServiceWorkPermi()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 5
                        select service).SingleOrDefault();
            return data;
        }

        public Service GetAirTicket()
        {
            var data = (from service in Singleton.DataContext.Services
                        where service.ID == 6
                        select service).SingleOrDefault();
            return data;
        }

        public List<Service> GetAll()
        {
            return (from s in Singleton.DataContext.Services
                    select s).ToList();
        }

        public Service Get(int id)
        {
            return (from s in Singleton.DataContext.Services
                    where s.ID == id
                    select s).SingleOrDefault();
        }

        public void Insert(Service newService)
        {
            Singleton.DataContext.Services.InsertOnSubmit(newService);
            Singleton.DataContext.SubmitChanges();
        }

        public void Update(Service updatedService)
        {
            Service service = (from s in Singleton.DataContext.Services
                               where s.ID == updatedService.ID
                               select s).SingleOrDefault();
            if (service != null)
            {
                service.Name = updatedService.Name;
                service.Time = updatedService.Time;
                service.Title = updatedService.Title;
                service.Cost = updatedService.Cost;
                service.Details = updatedService.Details;
                service.NationalCost = updatedService.NationalCost;
                Singleton.DataContext.SubmitChanges();
            }
        }

        public void Delete(int id)
        {
            Service service = (from s in Singleton.DataContext.Services
                               where s.ID == id
                               select s).SingleOrDefault();
            if (service != null)
            {
                Singleton.DataContext.Services.DeleteOnSubmit(service);
                Singleton.DataContext.SubmitChanges();
            }
        }

        public void ModifyService(int id, string detail)
        {
            var data = (from about in Singleton.DataContext.Services
                        where about.ID == id
                        select about).SingleOrDefault();
            if (data != null)
            {
                data.Details = detail;
            }
            else
            {
                data = new Service();
                data.ID = id;
                data.Details = detail;
                Singleton.DataContext.Services.InsertOnSubmit(data);
            }

            Singleton.DataContext.SubmitChanges();
        }
    }
}
